function dT = chebyshev_dnbasis(N, x, n)
% 有bug
% 给出一个函数，给定切比雪夫多项式的个数，计算在某一数值x下的第一类切比雪夫多项式的任意阶导数，要求输入N为切比雪夫多项式个数，x为切比雪夫多项式定义域内一点，返回0-N-1阶切比雪夫多项式的导数，组成一个N*1的行向量
% CHEBYSHEV_DNBASIS Calculate n-th derivative of Chebyshev polynomials
% Inputs:
%   N: Number of Chebyshev polynomials (0 to N-1)
%   x: Evaluation point in [-1,1]
%   n: Order of derivative
% Output:
%   dT: N×1 vector containing n-th derivatives of Chebyshev polynomials
error("bug");
    % Initialize output vector
    dT = zeros(N, 1);
    
    % Handle special cases
    if n == 0
        % Zero-th derivative (function values)
        dT(1) = 1;        % T_0(x) = 1
        if N > 1
            dT(2) = x;    % T_1(x) = x
            % Recurrence relation for higher orders
            for k = 3:N
                dT(k) = 2*x*dT(k-1) - dT(k-2);
            end
        end
    elseif n == 1
        % First derivative
        if N > 1
            dT(2) = 1;    % T_1'(x) = 1
            if N > 2
                dT(3) = 4*x;    % T_2'(x) = 4x
                % Recurrence relation for higher orders
                for k = 4:N
                    dT(k) = 2*(k-1)*dT(k-2);
                end
            end
        end
    else
        % Higher order derivatives
        for k = n+1:N
            % Using the formula for higher derivatives
            dT(k) = 2*(k-1)*chebyshev_dnbasis(k-1, x, n-1);
        end
    end
end
